<template>
  <div class="cloud-teller-manage" v-loading="loading" element-loading-text="加载中。。。">
    <div>
      <el-card class='cloud-teller-card'>
        <el-form ref='queryForm' :model='queryForm' size='mini' label-position='top'>
          <el-row :gutter="10">

            <el-col :md='6' :lg='4'>
              <el-form-item label='柜员号' prop='AGENTID'>
                <el-input v-model='queryForm.AGENTID' maxlength="8" placeholder="请输入柜员号"></el-input>
              </el-form-item>
            </el-col>

            <el-col :md='6' :lg='4'>
              <el-form-item label='柜员姓名' prop='AGENTNAME'>
                <el-input v-model='queryForm.AGENTNAME' maxlength="8" placeholder="请输入柜员姓名"></el-input>
              </el-form-item>
            </el-col>
               <el-col :md='6' :lg='4'>
              <el-form-item label='渠道码' prop='CHLCODE'>
                <el-input v-model='queryForm.CHLCODE' maxlength="8" placeholder="请输入渠道码"></el-input>
              </el-form-item>
            </el-col>

            <el-col :md="3" :lg="2" class="searchBtnMarginTop">
              <el-button type='primary' size='mini' icon='el-icon-search' @click="queryModel">查询</el-button>
            </el-col>
            <el-col :md="3" :lg="2" class="searchBtnMarginTop">
              <el-button type='warning' size='mini' icon='el-icon-refresh' @click="clearForm('queryForm')">重置</el-button>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <el-card style="margin-top: 10px">
      <el-col :lg="3" :md="2" v-if="btnPermission('Button_Warning_Add')">
              <el-button type="primary" size="mini" @click="addDialogShow" icon='el-icon-plus' >新增</el-button>
          </el-col>
        <el-table ref="tableData" :data='tableDataPage' border min-height="400" width='100%' class="tableMarginTop" header-row-class-name="tableHeaderClass"
          highlight-current-row>
          <!-- <el-table-column type="selection" width="40px"></el-table-column> -->
          <el-table-column prop='AGENTID' label='柜员工号'></el-table-column>
          <el-table-column prop='AGENTNAME' label='柜员姓名'></el-table-column>
          <el-table-column prop='CHLCODE' label='渠道码'></el-table-column>
          <el-table-column prop='CHLNAME' label='渠道名称'></el-table-column>
          <!-- <el-table-column prop='MAINTAINDATE' label='维护日期'></el-table-column> -->
          <el-table-column prop='REMARK' label='备注'></el-table-column>
          <el-table-column label='操作' align="center" fixed="right" width="150">
            <template slot-scope="scope">
              <el-button size="mini" type="primary" @click="handleClickDialog(scope.row)">维护</el-button>
              <el-button size="mini" type="danger" @click="handleDel(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination style="text-align:right;margin-top:20px;" v-show="this.tableData" :current-page="currentPage" background :page-size="pageSize"
          @current-change="changePage" layout="total, prev, pager, next, jumper" :total="tableData.length">
        </el-pagination>
      </el-card>
      <keep-alive>
        <component :is='dialogList.addTellerChannel' :option='addDialogOptions' @refreshTable="queryModel"></component>
      </keep-alive>
       <keep-alive>
        <component :is='dialogList.tellerChannel' :option='dialogOptions' @refreshTable="queryModel"></component>
      </keep-alive>
    </div>

  </div>
</template>

<script>
  import addTellerChannel from "./dialog/createTellerChannel";
  import tellerChannel from "./dialog/tellerChannel";
  import selectTree from "@/components/selectTree2/";
  import getGlobalParams from '@/common/utils/getGlobalParams';
  //通讯相关
  import request from "@/common/utils/requestCT";
  import tellerChannelQuery from "@/message/CTManage/teller-channel/teller-channel-query";
  import tellerChannelDel from "@/message/CTManage/teller-channel/teller-channel-del";

  export default {
    name: "cloud-teller-manage",
    components: {
      selectTree
    },
    data() {
      return {
        //页面公用
        loading: false,
        //表格
        tableTotal: 0,
        tableData: [],
        currentPage: 1,
        pageSize: getGlobalParams.get("PageSize"),
        delButtonShow: false,
        updateButtonShow: false,
        queryForm: {
          AGENTID: '',
          AGENTNAME: '',
          CHLCODE:''
        },
        currentRow: [],
        dialogList: {
          tellerChannel,
          addTellerChannel
        },
        dialogOptions: {
          isShow: false,
          font: '',
          currentRow: {}
        },
        addDialogOptions: {
          isShow: false,
          font: '',
          currentRow: {}
        },
      };
    },
    mounted() {
      this.queryModel();
    },
    computed: {
      tableDataPage() {
        return this.tableData.slice((this.currentPage - 1) * this.pageSize, this.currentPage * this.pageSize);
      }
    },
    methods: {
      // 点击新增修改按钮事件
      addDialogShow() {
        // this.dialogOptions.currentRow = row;
        this.addDialogOptions.isShow = !this.addDialogOptions.isShow;
      },
      // 点击修改按钮事件
      handleClickDialog(row) {
        this.dialogOptions.currentRow = row;
        this.dialogOptions.isShow = !this.dialogOptions.isShow;
      },

      changePage(val) {
        this.currentPage = val
      },
      clearForm(item) {
        this.$refs["" + item].resetFields();
      },
      async queryModel() {
        this.loading = true;
        this.tableData = [];
        this.tableTotal = 0;
        let resBody = new tellerChannelQuery();

        resBody.data.AGENTID = this.queryForm.AGENTID;
        resBody.data.AGENTNAME = this.queryForm.AGENTNAME;
        resBody.data.CHLCODE = this.queryForm.CHLCODE

        resBody.QueryPageNo = this.currentPage;
        resBody.QueryRowNum = this.pageSize;
        let response = await request(resBody);

        this.loading = false;
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.tableData = response.RSP_BODY.resultSet;
          this.tableTotal = response.RSP_BODY.total * 1 
          // || response.QUERY_INFO_HEAD.QueryAllDataCount;
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          });
        }
      },

      handleDel(row) {
        console.log(row)
        this.$confirm("此操作将永久删除" + row.AGENTNAME + "的关联关系 是否继续？", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(() => {
            this.delFun(row);
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除"
            });
          });
      },

      async delFun(row) {
        this.loading = true;
        let resBody = new tellerChannelDel();
        resBody.data.AGENTID = row.AGENTID;
        resBody.data.CHLCODE = row.CHLCODE;
        let response = await request(resBody);
        this.loading = false;
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.$message({
            type: "success",
            message: "柜员对应渠道关系解除成功!"
          });
          this.queryModel();
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          });
          this.loading = false;
        }
      },

      handleSizeChange() {
        this.queryModel();
      },
    },

    async created() {}
  };

</script>


<style lang="scss" scoped>
  .el-date-editor.el-input {
    width: 100% !important;
  }

  .el-card {
    overflow: inherit;
  }

</style>
